package org.poseidon.report.controller;

import org.poseidon.common.annotation.Log;
import org.poseidon.common.core.controller.BaseController;
import org.poseidon.common.core.domain.CommonResult;
import org.poseidon.common.core.page.TableDataInfo;
import org.poseidon.common.enums.BusinessType;
import org.poseidon.common.utils.poi.ExcelUtil;
import org.poseidon.report.domain.BuReport;
import org.poseidon.report.service.IBuReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 记录Controller
 * 
 * @author gfc
 * @date 2022-02-22
 */
@RestController
@RequestMapping("/report/report")
public class BuReportController extends BaseController
{
    @Autowired
    private IBuReportService buReportService;

    /**
     * 查询记录列表
     */
    @PreAuthorize("@ss.hasPermi('report:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuReport buReport)
    {
        startPage();
        List<BuReport> list = buReportService.selectBuReportList(buReport);
        return getDataTable(list);
    }

    /**
     * 导出记录列表
     */
    @PreAuthorize("@ss.hasPermi('report:report:export')")
    @Log(title = "记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuReport buReport)
    {
        List<BuReport> list = buReportService.selectBuReportList(buReport);
        ExcelUtil<BuReport> util = new ExcelUtil<BuReport>(BuReport.class);
        util.exportExcel(response, list, "记录数据");
    }

    /**
     * 获取记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:report:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Integer id)
    {
        return CommonResult.success(buReportService.selectBuReportById(id));
    }

    /**
     * 新增记录
     */
    @PreAuthorize("@ss.hasPermi('report:report:add')")
    @Log(title = "记录", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody BuReport buReport)
    {
        return toAjax(buReportService.insertBuReport(buReport));
    }

    /**
     * 修改记录
     */
    @PreAuthorize("@ss.hasPermi('report:report:edit')")
    @Log(title = "记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody BuReport buReport)
    {
        return toAjax(buReportService.updateBuReport(buReport));
    }

    /**
     * 删除记录
     */
    @PreAuthorize("@ss.hasPermi('report:report:remove')")
    @Log(title = "记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buReportService.deleteBuReportByIds(ids));
    }
}
